﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OracleClient;
using BCNPCObject.DB;
using DbLinq;
using DbLinq.Oracle;
using CMISLibrary.Entities;
using CMISLibrary;
namespace BCNPCObject.EXCEL
{
    public class cls_DD_BDONG_CTO_Controller
    {
        #region   Atributes

        //private DataSet CMIS_Header = new CMISOutputParameter();
        private DD_BDONG_CTO info;

        #endregion

        #region   Constructor

        public cls_DD_BDONG_CTO_Controller()
        {
            info = new DD_BDONG_CTO();
        }
        public cls_DD_BDONG_CTO_Controller(DD_BDONG_CTO Info)
        {
            this.info = Info;
        }

        #endregion

        #region   Properties

        public DD_BDONG_CTO pInfor
        {
            get { return info; }
            set { info = value; }
        }
        #endregion

        #region Methods
        public bool insert_DD_BDONG_CTO(ref string maloi)
        {
            //long _ID = CMIS2.DB.ExecuteCommand("Select SEQ_HDG_HOP_DONG.NEXTVAL from dual");
            //if (_ID == -1) return false;
            try
            {
                //info.HDG_KHACH_HANG = Convert.ToInt64(_ID);
                DD_BDONG_CTO objDD_BDONG_CTO = new DD_BDONG_CTO()
                {
                    MA_DVIQLY = info.MA_DVIQLY,
                    ID_BBAN = info.ID_BBAN,
                    MA_DDO = info.MA_DDO,
                    MA_CTO = info.MA_CTO,
                    SO_CTO = info.SO_CTO,
                    LAN = info.LAN,
                    MA_BDONG = info.MA_BDONG,
                    NGAY_BDONG = info.NGAY_BDONG,
                    MA_CLOAI = info.MA_CLOAI,
                    LOAI_CTO = info.LOAI_CTO,
                    VTRI_TREO = info.VTRI_TREO,
                    MA_SOCBOOC = info.MA_SOCBOOC,
                    SO_VIENCBOOC = info.SO_VIENCBOOC,
                    MA_SOCHOM = info.MA_SOCHOM,
                    SO_VIENCHOM = info.SO_VIENCHOM,
                    SO_COT = info.SO_COT,
                    SO_HOM = info.SO_HOM,
                    MA_CNANG = info.MA_CNANG,
                    NGAY_TAO = info.NGAY_TAO,
                    NGUOI_TAO = info.NGUOI_TAO,
                    NGAY_SUA = info.NGAY_SUA,
                    NGUOI_SUA = info.NGUOI_SUA
                };
                CMIS2.DB.DD_BDONG_CTO.InsertOnSubmit(info);
                CMIS2.DB.SubmitChanges();
                //id_HDG_HOP_DONG = _ID;
                CMIS2.ResetDB();
                return true;
            }
            catch (Exception ex)
            {
                maloi = ex.ToString();
                CMIS2.ResetDB();
                return false;
            }
        }
        public bool delete_DD_BDONG_CTO(DataTable dt, ref string maloi)
        {
            try
            {
                if (dt != null && dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Columns.Count; i++)
                    {
                        var query = from p in CMIS2.DB.DD_BDONG_CTO
                                    where (p.MA_DVIQLY == dt.Rows[i]["MA_DVIQLY"].ToString() && p.MA_DDO == dt.Rows[i]["MA_DDO"].ToString() && p.ID_BBAN == Convert.ToInt64(dt.Rows[i]["ID_BBAN"]) && p.MA_CTO == dt.Rows[i]["MA_CTO"].ToString() && p.LAN == 1)
                                    select p;
                        if (query != null && query.Count() > 0)
                        {
                            CMIS2.DB.DD_BDONG_CTO.DeleteAllOnSubmit(query.ToList());
                            CMIS2.DB.SubmitChanges();
                        }
                    }
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                maloi = ex.ToString();
                CMIS2.ResetDB(); return false;
            }
        }
        #endregion
    }
}
